import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    //根路由
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue'),
    // 根路由的二级路由
    children: [
      {
        // 首页
        path: "/home",
        name: "Home",
        alias: "",
        component: () => import("../views/Home.vue")
      },
      {
        // 菜单页
        path: "/menu",
        name: "Menu",
        component: () => import("../views/Menu.vue")
      },
      {
        // 购物车页面
        path: "/Shopbag",
        name: "Shopbag",
        component: () => import("../views/Shopbag.vue")
      },
      {
        // 我的页面
        path: "/my",
        name: "My",
        component: () => import("../views/My.vue")
      }
    ]
  },
  // 一级路由 商品详情页
  {
    path: "/detailed",
    name: "Detailed",
    component: () => import("../views/Detailed.vue")
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue")
  },
  {
    path: "/confirmOrder",
    name: "ConfirmOrder",
    component: () => import("../views/ConfirmOrder.vue")
  },
  {
    path: "/selectAddress",
    name: "SelectAddress",
    component: () => import("../views/SelectAddress.vue")
  },
  {
    path: "/addAddress/",
    name: "AddAddress",
    component: () => import("../views/AddAddress.vue")
  },
  {
    path: "/findAccountInfo/",
    name: "FindAccountInfo",
    component: () => import("../views/FindAccountInfo.vue")
  },
  {
    path: "/myOrder/",
    name: "MyOrder",
    component: () => import("../views/MyOrder.vue")
  },
  {
    path: "/mycollections/",
    name: "Mycollections",
    component: () => import("../views/Mycollections.vue")
  },
  {
    path: "/search/",
    name: "Search",
    component: () => import("../views/Search.vue")
  },
  {
    path: "/securityCenter/",
    name: "SecurityCenter",
    component: () => import("../views/SecurityCenter.vue")
  },
  {
    path: "/retrievethepassword/",
    name: "Retrievethepassword",
    component: () => import("../views/Retrievethepassword.vue")
  },
  {
    path: "/FindPasswordnext/",
    name: "FindPasswordnext",
    component: () => import("../views/FindPasswordnext.vue")
  }
]

const router = new VueRouter({
  routes
})


//--------------------------------------------------------------------------------------------
// 原因： 这个错误是vue-router内部错误,导致导航跳转问题,往同一地址跳转时会报错的情况push和replace 都会导致这个情况的发生。
// 解决编程式路由往同一地址跳转时会报错的情况
// const originalPush = VueRouter.prototype.push;
// const originalReplace = VueRouter.prototype.replace;
// //push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject)
//     return originalPush.call(this, location, onResolve, onReject);
//   return originalPush.call(this, location).catch(err => err);
// };
// //replace
// VueRouter.prototype.replace = function push(location, onResolve, onReject) {
//   if (onResolve || onReject)
//     return originalReplace.call(this, location, onResolve, onReject);
//   return originalReplace.call(this, location).catch(err => err);
// };
// -----------------------------------------------------------------------------


export default router
